package cn.learn.async.service;

import cn.learn.async.domian.TaskDemo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @author huangyezhan
 * @version 1.0
 * @date 2021年05月30日12:09
 */
@Component
public class AsyncService3 {

    private static int var = 1;

    @Async
    public Future<TaskDemo> testAsync1(TaskDemo task) {
        try {
            String name = Thread.currentThread().getName();
            System.out.println("当前线程名称：" + name + " ID:" + Thread.currentThread().getId());
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        task.setValue(task.getName() + "：" + var);
        var++;
        return new AsyncResult<>(task);
    }

}
